#coding: utf-8
from pyYahoo import YMap, YQuerySet
import unittest 

class YMapTest(unittest.TestCase):
    def test_YMap(self):
        map = YMap()
        results = map.searchName_by_keyword(q=u"경기대")
        for result in results:
            print result
        
class YQuerySetTest(unittest.TestCase):
    def test_iterableQuerySet(self):
        data = [
                {'name':u'testName1', 'something':u'else1'},
                {'name':u'testName2', 'something':u'else2'},
                {'name':u'testName3', 'something':u'else3'}
                ]
        querySet = YQuerySet(data)
        
        expectedList = list(iter(querySet))
        for idx, item in enumerate(data):
            self.assertEquals(expectedList[idx].name, item['name'].encode('utf-8'))
            
class YDistanceTest(unittest.TestCase):
    def setUp(self):
        self.map = YMap()
        self.from_lat = '37.26394379292282'
        self.from_lon = '127.02478408813477'
        self.to_lat = '37.26317531551517'
        self.to_lon = '127.04785108566284'
        
    def test_get_distance(self):
        distance = self.map.get_distance(self.from_lat, self.from_lon, self.to_lat, self.to_lon)
        self.assertEquals(50, distance)

if __name__ == "__main__":
    unittest.main()
